package dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DaoLogin extends DaoGeneric<LoginObject> {

	private final static String TABLENAME = DbTables.USER_LOGIN.toString();

	public DaoLogin(java.sql.Connection con) {
		super(con, TABLENAME);
	}

	public final static String LOGIN_NAME = "login_name";
	public final static String LOGIN_PW = "login_pw";

	public boolean login(String passText, String userText) {
		String query = "SELECT " + LOGIN_NAME + "," + LOGIN_PW + " FROM "
				+ TABLENAME + " WHERE " + LOGIN_NAME + "= ?" + " AND "
				+ LOGIN_PW + "= ?";
		try {
			PreparedStatement login = con.prepareStatement(query);

			login.setString(1, userText);
			login.setString(2, passText);

			ResultSet res = login.executeQuery();

			if (!res.next()) {
				return false;
			}
		} catch (SQLException e) {
			e.printStackTrace();
			return false;
		}

		return true;
	}

}
